import {Injectable} from '@angular/core';
import {Nav} from '../../models/nav';
import {HttpClient} from '@angular/common/http';
import {Observable} from 'rxjs/Observable';

const url: string = '/api/nav';

@Injectable()
export class NavService {

  /*getHeroes() {
    return Promise.resolve(HEROES);
  } */

  // See the "Take it slow" appendix
  // getHeroesSlowly()
  // { return new Promise<Hero[]>(resolve => setTimeout(() => resolve(HEROES), 2000) // 2 seconds  ); } }

  openNavs: Array<Nav>;

  /*调节左边菜单栏变化,默认为首页*/
  index: number = 0;

  /*控制右边内容组件显示,默认显示首页*/
  indexContent: number = 0;

  constructor(private httpClient: HttpClient) {

  }

  getAllNav(): Observable<Array<Nav>> {
    return this.httpClient.get<Array<Nav>>(`${url}/list`);
  }

  getAllNavItems(): Observable<Array<Nav>> {
    return this.httpClient.get<Array<Nav>>(`${url}/getAllNavItems`);
  }

}
